package com.njlime.cms.repository.app;

import com.njlime.cms.entities.CommunityCommentUp;
import com.njlime.cms.entities.CommunityUp;
import com.njlime.core.base.repository.impl.BaseDaoImpl;
import com.njlime.core.helper.PageBean;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Dean on 2017/10/10.
 */
@Repository
public class AppCommunityCommentUpDaoImpl extends BaseDaoImpl<CommunityCommentUp> {

    /**
     * 点赞列表
     * @param pageBean
     * @param info
     * @return
     */
    public PageBean list(PageBean pageBean, CommunityCommentUp info) {
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("select * from t_community_comment_up and comment_id = ?");
        arrList.add(info.getCommunity_id());
        int num = getListJdbcSize(sb.toString(), arrList);
        pageBean.setTotalCount(num);
        if (num > 0) {
            sb.append(" order by id desc limit ?,?");
            arrList.add((pageBean.getCurPage() - 1) * pageBean.getPageSize());
            arrList.add(pageBean.getPageSize());
            pageBean.setMapList(getListJdbc(sb.toString(), arrList));
        }
        return pageBean;
    }

    /**
     * 数量
     * @param commentId
     * @param userId
     * @return
     */
    public int userUpCount(int commentId, int userId) {
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("select * from t_community_comment_up where comment_id  = ? and up_user_id = ?");
        arrList.add(commentId);
        arrList.add(userId);
        return getListJdbcSize(sb.toString(),arrList);
    }
    /**
     * 删除
     *
     * @param commentId
     * @return
     */
    public int del(int commentId,Integer userId) {
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append(" DELETE FROM t_community_comment_up WHERE comment_id = ? and up_user_id = ?");
        arrList.add(commentId);
        arrList.add(userId);
        return updateJdbc(sb.toString(), arrList);
    }
}
